import {createStore} from "redux"

interface IAction {
    type: string,
    Value?: any,
    commentsId?:number
}
interface IState {
    article_id: number | undefined,
    comments_id: number | undefined
}
const reducer = (prevState: IState = {
                     article_id: 0,
                     comments_id: 0
                 },
                 action: IAction) => {
    const {type, Value,commentsId} = action
    const newState = JSON.parse(JSON.stringify(prevState))
    switch (type) {
        case "change":
            newState.article_id = Value
            return newState
        case "change_comments":
            newState.comments_id= commentsId
            return newState
        default:
            return prevState
    }
}

const store = createStore(reducer)
export default store
